//
//  PywResetAbsolutePwdSuccessController.m
//  PywSdk
//
//  Created by smallwave on 16/8/30.
//  Copyright © 2016年 zero. All rights reserved.
//

#import "PywResetAbsolutePwdSuccessController.h"
#import "UILabel+Pyw.h"
#import "UIButton+Pyw.h"
#import "PywMasonry.h"
#import "PywAccountManagerViewController.h"

@interface PywResetAbsolutePwdSuccessController ()

@property (nonatomic, strong) UILabel   *accountInfoLabel;  // 账号信息
@property (nonatomic, strong) UILabel   *promptInfoLabel;   // 提示信息
@property (nonatomic, strong) UIButton  *backBtn;           // 返回按钮

@property (nonatomic, copy) NSString    *account;           // 游戏账号
@property (nonatomic, copy) NSString    *loginPwd;          // 登录密码

@end

@implementation PywResetAbsolutePwdSuccessController

#pragma mark - Init
- (instancetype)initWithGameAccount:(NSString *)account
                           LoginPwd:(NSString *)loginPwd{
    self = [super init];
    if (self) {
        self.account = account;
        self.loginPwd = loginPwd;
    }
    return self;
}

#pragma mark - Lift Cycle Method
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setUp];
}

#pragma mark - prepareUI
- (void)setUp{
    self.title = @"设置成功";
    self.navigationItem.rightBarButtonItem = nil;
    self.automaticallyAdjustsScrollViewInsets = NO;
    [self leftBarButtonItem];
    
    [self addSubviewAndLayoutSubviews];
}
- (void)leftBarButtonItem{
    UIButton *back = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
    back.backgroundColor = [UIColor clearColor];
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:back];
    self.navigationItem.leftBarButtonItem = item;
}
- (void)addSubviewAndLayoutSubviews{
    [self.view addSubview:self.accountInfoLabel];
    [self.view addSubview:self.promptInfoLabel];
    [self.view addSubview:self.backBtn];
    
    __weak typeof(self) wSelf = self;
    [self.accountInfoLabel mas_makeConstraints:^(PywMASConstraintMaker *make) {
        make.centerX.offset(0);
        make.top.equalTo(wSelf.view.mas_top).offset(80);
    }];
    [self.promptInfoLabel mas_makeConstraints:^(PywMASConstraintMaker *make) {
        make.centerX.offset(0);
        make.top.equalTo(wSelf.accountInfoLabel.mas_bottom).offset(20);
        make.width.equalTo(wSelf.view.mas_width).multipliedBy(0.85);  
    }];
    [self.backBtn mas_makeConstraints:^(PywMASConstraintMaker *make) {
        make.centerX.offset(0);
        make.top.equalTo(wSelf.promptInfoLabel.mas_bottom).offset(40);
        make.width.equalTo(wSelf.promptInfoLabel.mas_width);
        make.height.equalTo(@40);
    }];
}
#pragma mark - Action
// 返回“游戏账号管理"
- (void)backAction{
    [self.view endEditing:YES];
    
    for (UIViewController *viewController in self.navigationController.viewControllers) {
        if ([viewController isKindOfClass:[PywAccountManagerViewController class]]) {
            [self.navigationController popToViewController:viewController animated:YES];
            break;
        }
    }
}
#pragma mark - Lazy
- (UILabel *)accountInfoLabel{
    if (!_accountInfoLabel) {
        _accountInfoLabel = [UILabel labelWithText:nil
                                     textAlignment:NSTextAlignmentLeft
                                          fontSize:14
                                         textColor:UIColorFromRGB(0x333333)];
        
        NSString *attributedStr = [NSString stringWithFormat:@"游戏账号：%@\n\n登录密码：%@",self.account,self.loginPwd];
        NSMutableAttributedString *attributedMessage = [[NSMutableAttributedString alloc] initWithString:attributedStr];
        // 设置不同的显示颜色
        [attributedMessage addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0xFFBC00) range:NSMakeRange(5, self.account.length)];
        [attributedMessage addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0xFFBC00) range:NSMakeRange(12 + self.account.length, self.loginPwd.length)];
        _accountInfoLabel.attributedText = attributedMessage;
        [_accountInfoLabel sizeToFit];
    }
    return _accountInfoLabel;
}
- (UILabel *)promptInfoLabel{
    if (!_promptInfoLabel) {
        _promptInfoLabel = [UILabel labelWithText:@"您也可以用游戏账号和独立密码登录游戏"
                              textAlignment:NSTextAlignmentCenter
                                   fontSize:14
                                  textColor:UIColorFromRGB(0x333333)];
    }
    return _promptInfoLabel;
}
- (UIButton *)backBtn{
    if (!_backBtn) {
        _backBtn = [UIButton buttonWithBackgroundColor:UIColorFromRGB(0xFFBC00)
                                          cornerRadius:20
                                            titleColor:[UIColor whiteColor]
                                    titleLabelFontSize:18
                                                 title:@"返回"];
        
        [_backBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
        [_backBtn setAccessibilityIdentifier:@"alonepwsd_back"];
    }
    return _backBtn;
}

@end
